import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { WineService } from 'src/app/service/wine.service';

@Component({
  selector: 'app-winelist',
  templateUrl: './winelist.component.html',
  styleUrls: ['./winelist.component.scss'],
  providers: [WineService]
})
export class WinelistComponent implements OnInit {
  uid: any;
  source = 'all';
  pageIndex = 1;
  pageSize = 15;
  footTotal = '';
  total = 1;
  dataSet = [];
  loading = true;
  isOkLoading = false;
  isVisible = false;
  starttime: any;
  endtime: any;
  sourcelist = [{ key: 'all', value: '全部' }, { key: 1, value: '买单消费' }, { key: 2, value: '升级会员' }, { key: 3, value: '邀请奖励' }, { key: 4, value: '活动奖励' }];
  constructor(private service: WineService, private ar: ActivatedRoute) {
    if (this.ar.routeConfig.path === 'winelistUid/:id') {
      this.uid = this.ar.snapshot.params.id;
    }
  }
  ngOnInit() {
    this.searchData();
  }

  searchData(reset: boolean = false): void {
    this.loading = true;
    this.service.query({
      offset: this.pageIndex,
      limit: this.pageSize,
      uid: this.uid,
      source: this.source,
      starttime: this.starttime,
      endtime: this.endtime
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows.map((item) => {
        item.mername =  item.mername ? item.mername : '平台';
        return item;
      });
      this.footTotal = res.footTotal; // 如: 共计 1200 元，酒币 2000 个，餐币 150 个
    });
  }

}
